package com.pxxy.cels.util;

import java.util.Scanner;

/**
 * @program: Cels
 * @package: qikran.cels.util
 * @description: ${和InputUtil中的正则表达式进行对输入数据的匹配验证  检查它是否符合要求
 * 如果符合要求 则返回在键盘上输入的值
 * 如果不符合要求  则要求用户一直输入}
 * @author: qi_kran
 * @create: 2020-04-08 14:20
 **/
public class VerifyFactory {
    public static final int TYPE_INT_0_2 = 1;
    public static final int TYPE_INT_0_3 = 2;
    public static final int TYPE_STRING_A_Z = 3;
    public static final int TYPE_STRING_Q = 4;
    public static final int TYPE_STRING_YN = 5;
    public static final int TYPE_INT_NUMBER = 6;
    public static final int TYPE_INT_NUMBER_5_55 = 7;
    public static final int TYPE_STRING_CN_Q = 8;
    public static final int TYPE_STRING_EN_Q = 9;

    public static Object verify(int verifyType) {
        Object o = null;
        switch (verifyType) {
            case TYPE_INT_0_2:
                o = getInputData(InputUtil.FORMAT_REGEX_0_2);
                break;
            case TYPE_INT_0_3:
                o = getInputData(InputUtil.FORMAT_REGEX_0_3);
                break;
            case TYPE_STRING_Q:
                o = getInputData(InputUtil.FORMAT_REGEX_Q);
                break;
            case TYPE_STRING_A_Z:
                o = getInputData(InputUtil.FORMAT_REGEX_A_Z);
                break;
            case TYPE_STRING_YN:
                o = getInputData(InputUtil.FORMAT_REGEX_YN);
                break;
            case TYPE_INT_NUMBER:
                o = getInputData(InputUtil.FORMAT_REGEX_NUMBER);
                break;
            case TYPE_INT_NUMBER_5_55:
                o = getInputData(InputUtil.FORMAT_REGEX_NUM_5_55);
                break;
            case TYPE_STRING_CN_Q:
                o = getInputData(InputUtil.FORMAT_REGEX_CN_Q);
                break;
            case TYPE_STRING_EN_Q:
                o = getInputData(InputUtil.FORMAT_REGEX_EN_Q);
                break;
            default:
                break;
        }
        return o;
    }

    private static Object getInputData(String regex) {
        boolean b = false;
        String s;
        Scanner scanner = new Scanner(System.in);
        do {
            s = scanner.nextLine();
            if (s.trim().length() <=0) {
                System.out.println("输入不合法，请重新输入");
                System.out.println("---------------------");
            } else {
                b = InputUtil.letterInput(regex, String.valueOf(s));
                if (!b) {
                    System.out.println("输入不合法，请重新输入");
                    System.out.println("---------------------");
                }
            }
        } while (!b);
        return s;
    }
}
